package com.travelbid.admin.struts.action;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LogoutAction extends Action{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
//		session.removeAttribute("user");
//		session.removeAttribute("USER_ID");
//		session.removeAttribute("USER_NAME");
//		session.removeAttribute("USER_NICK_NAME");
		Cookie nameCookie = null;
		Cookie passCookie = null;
		Cookie[] cookieset = request.getCookies();
		for (int i = 0; i < cookieset.length; i++) {
			if (cookieset[i].getName().equals("Name")){
				nameCookie = cookieset[i];
				nameCookie.setMaxAge( 0); 
				response.addCookie(nameCookie); 
			}
			else if (cookieset[i].getName().equals("Pass")){
				passCookie = cookieset[i];
				passCookie.setMaxAge(0);
				response.addCookie(passCookie); 
			}
		}
			
		session.invalidate();
		return mapping.findForward("Logout");
	}

}

